package com.rndemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import javax.annotation.Nullable;

/**
 * Created by tzj on 2018/4/12.
 */
public class RNCommonActivity extends BaseRNActivity {
    public static void startForResult(Activity context,Bundle bundle,String name) {
        Intent starter = new Intent(context, RNCommonActivity.class);
        if(bundle == null){
            bundle = new Bundle();
        }
        if(name!=null){
            starter.putExtra("component",name);
        }else{
            starter.putExtra("component",bundle.getString("component"));
        }
        starter.putExtras(bundle);
        context.startActivityForResult(starter,0);
    }

    @Nullable
    @Override
    protected String getMainComponentName() {
        if(super.getMainComponentName()==null){
            Intent intent = getIntent();
            if(intent!=null){
                return intent.getStringExtra("component");
            }
        }
        return super.getMainComponentName();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if(intent!=null){
            setContentView(intent.getStringExtra("component"),intent.getExtras());
        }
    }
}
